-
An
MGLStyle
object represents the active map style of anMGLMapView
. A style defines both the map’s content and every aspect of its appearance. Styles can be designed in Mapbox Studio and hosted on mapbox.com.MGLStyle
provides methods for inspecting and manipulating a style dynamically, with classes and properties that parallel the style JSON format defined by the Mapbox Style Specification.You set a map view’s active style using the
MGLMapView.styleURL
property.MGLStyle
provides a set of convenience methods that return the URLs of popular Mapbox-designed styles. Once the-[MGLMapViewDelegate mapView:didFinishLoadingStyle:]
or-[MGLMapViewDelegate mapViewDidFinishLoadingMap:]
method is called, signaling that the style has finished loading, you can use theMGLMapView.style
property to obtain the map view’sMGLStyle
.A style primarily consists of the following components:
- Content sources supply content to be shown on the map. Use methods such as
-sourceWithIdentifier:
and-addSource:
to configure the style’s content sources, which are represented byMGLSource
objects. - Style layers manage the layout and appearance of content at specific
z-indices in the style. Most kinds of style layers display content provided
by a content source. Use methods such as
-layerWithIdentifier:
and-addLayer:
to configure the style’s layers, which are represented byMGLStyleLayer
objects. - Style images are used as icons and patterns in style layers. Use the
-setImage:forName:
method to register an image as a style image. (Annotations are represented by annotation images rather than style images. To configure an annotation’s appearance, use the-[MGLMapViewDelegate mapView:imageForAnnotation:]
method.) - The style’s light is the light source affecting any 3D extruded fills.
Use the
light
property to configure the style’s light, which is represented by anMGLLight
object.
The
MGLStyle
,MGLSource
,MGLStyleLayer
, andMGLLight
classes are collectively known as the runtime styling API. The active style influences a related API, visible feature querying, which is available through methods such as-[MGLMapView visibleFeaturesInRect:]
.Some terminology differs between the Mapbox Style Specification and the various classes associated with
MGLStyle
. Consult the “Information for Style Authors” guide for an overview of these differences.Note
Wait until the map style has finished loading before modifying a map’s style via any of theMGLStyle
instance methods below. You can use the-[MGLMapViewDelegate mapView:didFinishLoadingStyle:]
or-[MGLMapViewDelegate mapViewDidFinishLoadingMap:]
methods as indicators that it’s safe to modify the map’s style.Declaration
Objective-C
@interface MGLStyle : NSObject
Swift
class MGLStyle : NSObject
- Content sources supply content to be shown on the map. Use methods such as
-
An
MGLStyleValue
object is a generic container for a style attribute value. The layout and paint attribute properties ofMGLStyleLayer
can be set toMGLStyleValue
objects.The
MGLStyleValue
class itself represents a class cluster. Under the hood, a particularMGLStyleValue
object may be either anMGLConstantStyleValue
to represent a constant value or one of the concrete subclasses ofMGLStyleFunction
to represent a value function. Do not initialize anMGLStyleValue
object directly; instead, use one of the class factory methods to create anMGLStyleValue
object.The
MGLStyleValue
class takes a generic parameterT
that indicates the Foundation class being wrapped by this class. Common values forT
include:NSNumber
(for Boolean values and floating-point numbers)NSValue
(forCGVector
,NSEdgeInsets
,UIEdgeInsets
, and enumerations)NSString
NSColor
orUIColor
NSArray
Declaration
Objective-C
@interface MGLStyleValue <T> : NSObject
Swift
class MGLStyleValue
-
Declaration
Objective-C
@interface MGLLight : NSObject
Swift
class MGLLight : NSObject